;
$(function () {
    var $pop = $('.pop_window1');
    var formData = new FormData();

    new ajax({
      url: 'user/user/saveUserInfo.do',
      type: 'post',
      processData: false,
      contentType: false,
      data: formData,
      success: function (data) {
        $("#member_modify_name").val(data.data.nickname)
      }
    })

    $('.member_modify_btn').on('click',  function () {
        $('#member_modify_name').val('')
    })

    $(".member_header").delegate('span', 'click', function () {

        const ix = $(this).index();
        switch (ix) {
            case 0:
                window.location.href = "member_info.html";
                break
            case 1:
                const val = $("#member_modify_name").val();
                if (val == "" || val.length > 12) {
                    $pop.children().html("昵称不能为空，长度不能大于12").end().show(function () {
                        const this_ = $(this);
                        setTimeout(function () {
                            this_.hide();
                            return;
                        }, 800);
                    });
                } else {
                    formData.append('nickname', val);
                    new ajax({
                        url: 'user/user/saveUserInfo.do',
                        type: 'post',
                        processData: false,
                        contentType: false,
                        data: formData,
                        success: function (data) {
                            localStorage.setItem("userInfo", JSON.stringify(data.data))
                            $pop.children().html("保存成功").end().show(function () {
                                const this_ = $(this);
                                setTimeout(function () {
                                    this_.hide();
                                    window.location.href = "member_info.html";
                                }, 800);
                            });
                        }
                    })
                }
        }
    })
})
